import axios from 'axios'
import {Toast} from 'vant'
import Loading from '../store/index.js'

const url = "http://152.136.185.210:7878/api/m5"
let config ={
  baseURL:url,
  timeout:10000
}
const _axios = axios.create(config);

// 使用拦截器拦截请求，显示加载中弹窗
_axios.interceptors.request.use(
  req =>{
    // 当state里的isLoading为true时再加载
    if(Loading.getters.Loading){
      Toast.loading({
        forbidClick:true,
        message:'加载中...'
      })
    }
    return req
  },
  err=>{
    return Promise.reject(err)
  });
  _axios.interceptors.response.use(
  res =>{
    Toast.clear()
    return res.data
  },
  err=>{
    Toast.clear()
    return Promise.reject(err)
  }
  )
  // 全局注册axios
  window.axios = _axios
// export  function request(config){
//   const instance = axios.create({
//   })
//   return instance(config)
// }
